home *** CD-ROM | disk | FTP | other *** search
/ .net 2002 March / DotNetMagazine-Issue107-Coverdisc-NET107-02-03-PCMac.bin / pc / PC Software / Coldfusion / coldfusion-60-win-en.exe / index.cfm26 < prev    next >
Encoding:
Text File  |  2002-03-18  |  3.2 KB  |  108 lines

  1. rved.
  2. *
  3. * YOUR RIGHTS WITH RESPECT TO THIS SOFTWARE IS GOVERNED BY THE
  4. * TERMS AND CONDITIONS SET FORTH IN THE CORRESPONDING EULA.
  5. *
  6. **
  7.  --->
  8.  
  9. <cfmodule template="../tags/bts_layout.cfm" exampleName="Custom Tags Example"
  10.     source="index.cfm,tempconverter.cfm"
  11.     keyTags="cfparam@Tags73.html,setVariable()@Functions211.html">
  12.  
  13.     <p>
  14. One of the easiest and most powerful ways to extend the functionality of
  15. ColdFusion is with custom tags. ColdFusion custom tags wrap
  16. functionality in one or more ColdFusion pages, which you can call from
  17. any other page.  This lets you add your own tags to the CFML language.
  18. You can write your own custom tags or use prebuilt custom tags that have
  19. been created by other developers. Macromedia offers a 
  20. <a href="http://devex.macromedia.com/developer/gallery/">Developer's Exchange</a> where you can
  21. download many custom tags for use in your applications. 
  22.     </p>
  23.     
  24.     <p>
  25. In the Custom Tags example, the temperature and scale from which to
  26. convert are passed as attributes to the custom tag, cf_tempconverter.
  27. The custom tag processes the conversion and returns the new value to the
  28. calling page as a variable called temp, which then displays on the page.
  29.     </p>
  30.     
  31.     <p>
  32. This modular approach to building applications provides benefits, such
  33. as easing code reuse, simplifying maintenance, and allowing distribution
  34. of application functionality. 
  35.     </p>
  36.         
  37. </cfmodule><!--- 
  38. **
  39. * CFMX Example Applications
  40. *
  41. * Copyright (c) 2002 Macromedia.  All Rights Reserved.
  42. *
  43. * YOUR RIGHTS WITH RESPECT TO THIS SOFTWARE IS GOVERNED BY THE
  44. * TERMS AND CONDITIONS SET FORTH IN THE CORRESPONDING EULA.
  45. *
  46. **
  47.  --->
  48.  
  49. <cfmodule template="../tags/layout.cfm" pageName="Custom Tags Example">
  50.  
  51. <p>
  52. This example shows the use of custom tags. Custom tags are a powerful
  53. way to add complex functionality to your web application. 
  54. </p>
  55.  
  56. <cfparam name="form.scaleFrom" default="F">
  57.  
  58. <!---
  59.     Based on the Scale abbreviation, set the display name of
  60.     the 'To' and 'From' scales.
  61. --->    
  62. <cfif IsDefined("form.temp") and isNumeric(form.temp)>
  63.     <cfif form.scaleFrom eq "F">
  64.         <cfset scaleFromName = "Fahrenheit">
  65.         <cfset scaleToName = "Celsius">
  66.     <cfelse>
  67.         <cfset scaleFromName = "Celsius">
  68.         <cfset scaleToName = "Fahrenheit">
  69.     </cfif>
  70.  
  71.     <!--- 
  72.         This is where we actually call the custom tag.
  73.         Note how we pass the variables. 
  74.     --->
  75.     <cf_tempconverter scale="#scaleFromName#" Temperature="#form.temp#" returnVariable="temp">
  76.     
  77.     <cfoutput>
  78.         <p>
  79.         #form.Temp# degrees #scaleFromName# =  #temp# degrees #ScaleToName#
  80.         </p>
  81.     </cfoutput>
  82.  
  83. </cfif>
  84.  
  85. <!---
  86.     The preserveData attribute will show the temperature in
  87.     its text box after the form has been posted.
  88. --->    
  89. <cfform action="#cgi.script_name#"
  90.         method="post"
  91.         preserveData="Yes">
  92.  
  93. <p>
  94. Convert Temperature from <cfinput type="Text" name="Temp" message="Temperature must be numeric." validate="float" required="Yes"> degrees
  95. </p>
  96.  
  97.  
  98. <table>
  99. <tr><td colspan="2">Scale:</td></tr>
  100. <tr>
  101.     <td>Fahrenheit</td>
  102.     <td><cfinput type="radio" name="scaleFrom" value="F" checked></td>
  103. </tr>
  104. <tr>
  105.     <td>Celsius</td>
  106.     <td><cfinput type="radio" name="scaleFrom" value="C"></td>
  107. </tr>
  108. </tab